package com.chengwang.bookstory.service.Imple;

import com.chengwang.bookstory.mapper.ShopMapper;
import com.chengwang.bookstory.pojo.MyShop;
import com.chengwang.bookstory.pojo.ShopList;
import com.chengwang.bookstory.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
@Transactional
public class ShopServiceImple implements ShopService {
    @Autowired
    private ShopMapper shopMapper;
    @Override
    public void add(String userAccount, String bookId, int shopNumber) {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dataTime = dateFormat.format(new Date());
        int i=shopMapper.add(userAccount,bookId,shopNumber,dataTime);
        if (i<1){
            shopMapper.add(userAccount,bookId,shopNumber,dataTime);
        }
    }

    @Override
    public List<ShopList> queryAllShop(String userAccount) {
        return shopMapper.queryAllShop(userAccount);
    }

    @Override
    public List<MyShop> queryAllMyShop(String userAccount) {
        return shopMapper.queryAllMyShop(userAccount);
    }

    @Override
    public void deleteAll(String userAccount) {
        shopMapper.deleteAll(userAccount);
    }

    @Override
    public void delById(String userAccount, String bookId,String time) {
        shopMapper.delById(userAccount,bookId,time);
    }
}
